<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import = "ac.kr.ml.vo.ContentVo" %>
<%@ page import="java.util.*" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="/mediaLogSNS/css/main.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="./jquery/jquery-1.9.0.js"></script>
<title>mediaLogSNS</title>
</head>
<body>
	
	<script>
		
	$(document).ready(function(){
		 
		Getlist();	
		$("#submit").click(function(){
			insert();
			
		});		
		
	});
	
	function replyView(idx) {
		$("#reply-div-"+idx).toggle();
		
	}
	function replySubmit(idx) {
		
		
	}
	
	
	function insert(){
		if($("#input-Text").val() == null || $("#input-Text").val() == ""){
			alert($("#input-Text").val());
			return;
		}
				
		$.ajax({
			type : "POST",
			url : "main",
			async : false,
			dataType:"JSON",
			data : {"a" : "write", "content" : $("#input-Text").val()},
			success : AddContent,
			error:function(xhr, status, error) { alert("ERROR"); }
		});			
	}
	
	function AddContent(json){
		
		
		var vo = json.content;
		
		var con_id = vo[0].con_id;
		var content = vo[0].content;
		var time = vo[0].time;
		var good = vo[0].good;
		var bad = vo[0].bad;
		var reply_cont = vo[0].reply_cont;
		
		$("#content-list-div").before('<p>'+content+'</p>');
		
	}
	
	function Getlist(){
		$.ajax({
			type : "POST",
			url : "main",
			async : false,
			contentType: "application/x-www-form-urlencoded; charset=UTF-8",
			data : {"a" : "list"},
			dataType : "JSON",
			success : makeTable,
	 

			error : function(xhr, status, error) { alert("xhr : " + xhr + "\nstatus : " + status +"\nerror : " + error); }
		
		});			
	}
	
	function makeTable(json){	
		
		
		
		var list = json.AnnoymousSNS;
		
		var row_count = list.length;			
		var html= ""
		for(var i = 0; i < row_count; i++){
			
			var con_id = list[i].con_id;
			var content = list[i].content;
			var time = list[i].time;
			var good = list[i].good;
			var bad = list[i].bad;
			var reply_cont = list[i].reply_cont;

				html+= "<tr>"
				html+= "<td>"
	//html+= "	<ul>";
	//html+= "<li>";
				html+= "			<span>"+time+"</span>";
				html+= "			<p>"+content+"</p>";
				html+= "			<a href=\"#\"> 좋아요 "+ good +"</a>"
									+ "<a href=\"#\"> 싫어요 " + bad +"</a>"
									+ "<a href=\"#\"> 덧글 " + reply_cont + "</a>";
	//html+="</li>";
	//html+="</ul>";
				html+="</td>";
				html+="</tr>";
		
				//위 혹은 아래로
		/*		
				//html+= "<tr>"
				//html+= "<td>"
		html+= "	<ul>";
		html+= "<li>";
					html+= "			<span>"+time+"</span>";
					html+= "			<p>"+content+"</p>";
					html+= "			<a herf=\"#\"> 좋아요 "+ good
										+ "</a><a href=\"#\"> 싫어요 " + bad
										+ "</a><a href=\"#\"> 덧글 " + reply_cont + "</a>";
		html+="</li>";
		html+="</ul>";
					//html+="</td>";
					//html+="</tr>";
				
		*/		


		}		
		$("#contentTable").html("");
		$("#contentTable").append(html);
	}
	
	</script>
	
	<div id ="container">
		<div id="header">
			<jsp:include page="/include/header.jsp"  flush="true" />
		</div>
		<div id="wrapper">			
			<div id="writeBox">
				<input type="text" id="input-Text" size ="70" maxlength="70" />
				<input type="button" VALUE="글쓰기" id="submit">
			</div><!-- writeBox End -->
			<table>
				<tbody id="contentTable"></tbody>
			</table>
												
		</div>
		<div id="navigation">
			<jsp:include page="/include/navigation.jsp"  flush="true" />
		</div>
		<div id="footer">
			<p>(c)mediaLog </p>
		</div>
	</div>
</body>
</html>